#region Using's

using System;
using System.Collections;
using System.Linq;
using System.Collections.Generic;

#endregion

namespace LightPersist.Metainfo
{
	public abstract class Constraint
	{
		public abstract ConstraintResult Process();
	}

	public class DummyConstraint : Constraint
	{
		public override ConstraintResult Process()
		{
			throw new NotImplementedException();
		}
	}

	public abstract class PropertyConstraint : Constraint
	{
		public string Class { set; get; }
		public string Property { set; get; }
	}

	public class NotEmty : PropertyConstraint
	{
		public override ConstraintResult Process()
		{
			var listOfClassesToProcess = new List<object>
			{
			}; //should be realy gotten from context
			foreach(var obj in listOfClassesToProcess)
			{
				if(obj.GetType().Name == Class)
				{
					if(CheckNotEmpty(obj) == ConstraintResult.Failed)
					{
						return ConstraintResult.Failed;
					}
				}
			}
			return ConstraintResult.Succeed;
		}

		ConstraintResult CheckNotEmpty(object target)
		{
			var property = target.GetType().GetProperty(Property);
			var value = property.GetValue(target, new object[]
			{
			});

			if(value is IList)
			{
				return ((IList)value).Count == 0 ? ConstraintResult.Failed : ConstraintResult.Succeed;
			}

			return (value == null) ? ConstraintResult.Failed : ConstraintResult.Succeed;
		}
	}

	public class Unique : PropertyConstraint
	{
		public override ConstraintResult Process()
		{
			throw new NotImplementedException();
		}
	}
}